<template>
  <div class="app-container d-flex">
    <div class="h-100 w-3">
      <!-- 3号楼4层总能耗 -->
      <div class="h-2 w-100 p10">
        <div class="h-100 w-100 item_border p10">
          <div class="item_title">
            <div class="d-flex align-items-center">
              <div class="success_point"></div>
              <div class="font-white font-14">3号楼4层总能耗<span class="font-12">（kW·h）</span></div>
            </div>
          </div>
          <div class="d-flex item_content pt10">
            <div class="h-100 w-50 pr-2">
              <div class="h-100 w-100 d-flex align-items-center item_bg_border">
                <div class="h-100 item_width item_bg_warning"></div>
                <div class="h-100 item_width2 d-flex flex-column p-4">
                  <div class="font-white font-14 mb-5">总控 用电量</div>
                  <div class="w-100 d-flex-center">
                    <div class="font-white-impact font-32 mr-2">{{oneCarData0}}</div>
                  </div>
<!--                  <div class="font-blue font-16 mt-2 text-right">kW·h</div>-->
                </div>
              </div>
            </div>
            <div class="h-100 w-50 pl-2">
              <div class="h-50 w-100 pb-2">
                <div class="h-100 w-100 d-flex align-items-center item_bg_border">
                  <div class="h-100 item_width item_bg_color1"></div>
                  <div class="h-100 item_width2 d-flex flex-column justify-content-around p-2">
                    <div class="font-white font-14">东总控 用电量</div>
                    <div class="w-100 d-flex-center">
                      <div class="font-white-impact font-32 mr-2">{{$formatNumber2(oneCarData1.deviceValue)}}</div>
<!--                      <div class="font-blue font-16 mt-2 text-right">kW·h</div>-->
                    </div>

                  </div>
                </div>
              </div>
              <div class="h-50 w-100 pt-2">
                <div class="h-100 w-100 d-flex align-items-center item_bg_border">
                  <div class="h-100 item_width item_bg_color2"></div>
                  <div class="h-100 item_width2 d-flex flex-column justify-content-around p-2">
                    <div class="font-white font-14">西总控 用电量</div>
                    <div class="w-100 d-flex-center">
                      <div class="font-white-impact font-32 mr-2">{{$formatNumber2(oneCarData2.deviceValue)}}</div>
<!--                      <div class="font-blue font-16 mt-2 text-right">kW·h</div>-->
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- 公共区域-->
      <div class="h-2 w-100 p10">
        <div class="h-100 w-100 item_border d-flex flex-wrap p10">
          <div class="height-33 w-50 p-2">
            <div class="d-flex align-items-center">
              <el-image class="image_size" :src="ggqy" fit="cover"></el-image>
              <div class="font-white font-24 ml-3">公共区域</div>
            </div>
          </div>
          <div class="height-33 w-50 p-2" v-for="(item,index) in twoCardData" :key="index">
            <div class="h-100 w-100 d-flex align-items-center item_bg_border">
              <div class="h-100 item_width" :class="titleBgcList[index]"></div>
              <div class="h-100 item_width2 d-flex flex-column justify-content-around p-1 pl-2">
                <div class="font-white font-12">{{titleList[index]}}</div>
                <div class="w-100 d-flex-center">
                  <div class="font-white-impact font-26 mr-2">{{$formatNumber2(item.deviceValue)}}</div>
                  <div class="font-blue font-12 mt-2 text-right">kW·h</div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!--3号楼4层能耗分布-->
      <div class="h-2 w-100 p10">
        <div class="h-100 w-100 item_border p10">
          <div class="item_title">
            <div class="d-flex align-items-center">
              <div class="success_point"></div>
              <div class="font-white font-14">3号楼4层能耗分布</div>
            </div>
          </div>
          <div class="item_content">
            <div class="h-100 w-100 pt-3" id="pie-first"></div>
          </div>
        </div>
      </div>
    </div>
    <div class="h-100 w-9">
      <!-- 3号楼4层房间总能耗 -->
      <div class="h-3 w-100 p10">
        <div class="h-100 w-100 item_border p10">
          <div class="item_title2">
            <div class="d-flex align-items-center">
              <div class="success_point"></div>
              <div class="font-white font-14">3号楼4层房间总能耗</div>
            </div>
          </div>
          <div class="item_content2">
            <div class="h-100 w-100">
              <div class="w-100 h-100 d-flex flex-wrap">
                <div class="width-15 height-33 p10" v-for="(item, index) in fourCarData" :key="index">
                  <div class="w-100 h-100 d-flex flex-column justify-content-between item_bg_border p10">
                    <div class="font-white font-14">{{fourCardTitle[index]}}</div>
                    <div class="d-flex-center">
                      <div class="font-white-impact font-32">{{$formatNumber2(item.deviceValue)}}</div>
                    </div>
                    <div class="d-flex justify-content-end">
                      <div class="font-blue font-12">kW·h</div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!--  -->
      <div class="h-3 w-100 p10">
        <!-- 3号楼4层房间能耗对比 -->
        <div class="h-100 w-100 item_border p10">
          <div class="item_title">
            <div class="d-flex align-items-center">
              <div class="success_point"></div>
              <div class="font-white font-14">3号楼4层房间能耗对比</div>
            </div>
          </div>
          <div class="item_content">
            <div class="h-100 w-100 pt-3" id="bar-first"></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import charts from './chart.js'
  import {
    queryOneListEnergyByNum,
    queryTwoListEnergyByNum,
    queryThreeListEnergyByReport,
    queryFourListEnergyByNum,
    queryFiveListEnergyByReport
  } from "@/api/dormThreeBuildingFourFloor/energyAnalysis"

  export default {
    components: {},
    data() {
      return {
        ggqy: require('@/assets/img/ggqy.png'),

        timeout: [],

        oneCarData0: 0,
        oneCarData1: {},
        oneCarData2: {},

        twoCardData: [],
        threeCardData: [],
        titleBgcList: ['item_bg_warning', 'item_bg_success', 'item_bg_danger', 'item_bg_color1', 'item_bg_color2', 'item_bg_success'],
        titleList: ['东过道照明', '西过道照明', '应急灯', '饮水机', '洗衣机'],

        fourCarData: [],
        fourCardTitle: ['3401室', '3402室', '3403室', '3404室', '3405室', '3406室', '3407室', '3408室', '3409室', '3410室', '3412室', '3413室', '3414室', '3415室', '3416室', '3417室', '3418室', '3419室'],
        fiveCardData: {
          xData: [],
          seriesData1: [],
          seriesData2: [],
          seriesData3: [],
        },
        sixCardData: {
          xData: [],
          seriesData1: [],
        },
      }
    },
    created() {
    },
    mounted() {
      this.queryOneListEnergyByNum()
      this.queryTwoListEnergyByNum()
      this.queryThreeListEnergyByReport()
      this.queryFourListEnergyByNum()
      this.queryFiveListEnergyByReport()

      let _this = this;
      this.timeout[0] = setInterval(() => {
        _this.queryOneListEnergyByNum()
        _this.queryTwoListEnergyByNum()
        _this.queryThreeListEnergyByReport()
        _this.queryFourListEnergyByNum()
        _this.queryFiveListEnergyByReport()
      }, 30000);

      // this.timeout[1] = setInterval(() => {

      // }, 30000);
    },
    beforeDestroy() {
      if (this.timeout.length > 0) {
        this.timeout.forEach(item => {
          clearInterval(item);
        })
      }
    },
    methods: {
      queryOneListEnergyByNum() {
        queryOneListEnergyByNum().then(res => {
          let tempData = res.object
          this.oneCarData1 = tempData[0]
          this.oneCarData2 = tempData[1]

          this.oneCarData0 = (this.$formatNumber2(tempData[0].deviceValue) + this.$formatNumber2(tempData[1].deviceValue)).toFixed(2)
        })
      },
      queryTwoListEnergyByNum() {
        queryTwoListEnergyByNum().then(res => {
          let tempData = res.object
          this.twoCardData = tempData

          let yjd = tempData[2].deviceValue
          let ysj = tempData[3].deviceValue

          let yjd2 = this.$subtractAndAssign(yjd, ysj)
          this.$set(this.twoCardData[2], 'deviceValue', yjd2);
        })
      },
      queryThreeListEnergyByReport() {
        queryThreeListEnergyByReport().then(res => {
          let tempData = res.object || []
          let tempData2 = []
          for (let i = 0; i < tempData.length; i++) {
            tempData2.push({
              value: this.$formatNumber2(tempData[i].yValue),
              name: tempData[i].xValue,
            })
          }

          this.threeCardData = tempData2

          charts.pieEchart('pie-first', this.threeCardData)
        })
      },
      queryFourListEnergyByNum() {
        queryFourListEnergyByNum().then(res => {
          let tempData = res.object || []

          this.fourCarData = tempData
        })
      },

      queryFiveListEnergyByReport() {
        queryFiveListEnergyByReport().then(res => {
          let tempData = res.object || []
          let xData = []
          let seriesData1 = []
          let seriesData2 = []
          let seriesData3 = []
          for (let i = 0; i < tempData.length; i++) {
            xData.push(tempData[i].xValue == '宿管间' ? tempData[i].xValue : tempData[i].xValue + '室')

            let arr = tempData[i].yValue.split(',')
            seriesData1.push(this.$formatNumber2(arr[0]))
            seriesData2.push(this.$formatNumber2(arr[1]))
            seriesData3.push(this.$formatNumber2(arr[2]))
          }

          this.fiveCardData.xData = xData
          this.fiveCardData.seriesData1 = seriesData1
          this.fiveCardData.seriesData2 = seriesData2
          this.fiveCardData.seriesData3 = seriesData3
          charts.barEchart('bar-first', this.fiveCardData)
        })
      },
    }
  }
</script>
<style lang="scss" scoped>
  .pt10 {
    padding-top: 10px;
  }

  .height-33 {
    height: 33.33%;
  }

  .height-20 {
    height: 18%;
  }

  .height-15 {
    height: 15%;
  }

  .width-77 {
    width: 76.67%;
  }

  .width-66 {
    width: 66.66%;
  }

  .width-33 {
    width: 33.33%;
  }

  .width-15 {
    width: 16.66%;
  }

  .item_width {
    width: 8px;
  }

  .item_width2 {
    width: calc(100% - 8px);
  }

  .item_bg_success {
    background-color: #1AA652;
  }

  .item_bg_warning {
    background-color: #FFB822;
  }

  .item_bg_danger {
    background-color: #FF6A93;
  }

  .item_bg_color1 {
    background-color: #87f7c7;
  }

  .item_bg_color2 {
    background-color: #1292b1;
  }

  .item_bg_border {
    background-color: #0A343D;
    border-radius: 4px;
    overflow: hidden;
  }

  .image_size {
    width: 56px;
    height: 56px;
  }

  .font-white {
    font-family: Source Han Sans CN, Source Han Sans CN-500;
    font-weight: 500;
    color: #ffffff;
  }

  .font-blue {
    font-family: Source Han Sans CN, Source Han Sans CN-500;
    font-weight: 500;
    color: #6CA7B4;
  }

  .font-white-impact {
    font-family: Impact, Impact-400;
    font-weight: 400;
    color: #ffffff;
  }

  .font-white-impact2 {
    font-family: Impact, Impact-400;
    font-weight: 400;
    color: #ffffff;
    text-shadow: 0px 0px 4px #16d0ff !important;
  }

  .font-white-impact3 {
    font-family: Impact, Impact-400;
    font-weight: 400;
    color: #ffffff;
    text-shadow: 0px 0px 4px #fed52f !important;
  }
</style>
